const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        msgs1: [],
        tabs2: ['小说目录', '小说简介', '小说评论'],
        activeIndex2: 0,
        bid: 0,
        id: '',
        je: 0,
        url: App.Config.basePath
    },

    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function () {
    },
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option,
                bid: option.id
            })
        }
    },
    onShow() {
        this.getMsgs1();
    },
    navigateTo(e) {
        App.navigateTo(e.currentTarget.dataset.url, e.currentTarget.dataset);
    },
    getMsgs1() {

        //调用数据
        let param = {
            f: 3,
            bid: this.data.bid,
            mid: wx.getStorageSync("mid"),
            loadmsg: `正在加载中`
        };

        App.HttpService.getData(param, "/books_List").then(data => {
            this.setData({
                msgs1: data
            });
        });
    },
    tabClick2: function (e) {
        const dataset = e.currentTarget.dataset;
        this.setData({
            activeIndex2: dataset.id
        });
    },



    formSubmit1: function (e) {
        var that = this;
        var data = e.detail.value;

        if (data.cmemo == "") {
            that.showModal("请输入评论内容");
            return;
        } else {
            data = App.Tools.extend(data, {
                id: this.data.bid,
                mid: wx.getStorageSync("mid")
            });
            App.HttpService.saveData(data, "/comment_Add").then(data => {
                App.WxService.showToast({
                    title: "评论成功!",
                    icon: 'success',
                    duration: 1000,
                });
                setTimeout(function () {
                    that.getMsgs1();
                }, 1000);
                that.setData({
                    cmemo: ''
                })
            });
        }


    },

    showModal2(e) {
        this.setData({
            modalName: e.currentTarget.dataset.target,
            id:e.currentTarget.dataset.id,
            je:e.currentTarget.dataset.je,
        })
    },
    hideModal(e) {
        this.setData({
            modalName: null
        })
    },

    pay(e){
        var that=this;
        var data = null;

        data = App.Tools.extend(data, {
            id: this.data.id,
            mid: wx.getStorageSync("mid"),
        });

        App.HttpService.saveData(data, "/bookshelf_Add").then(data => {
            App.WxService.showToast({
                title: "支付成功!",
                icon: 'success',
                duration: 1500,
            });
            setTimeout(function() {
                that.setData({
                    modalName: null
                })
                that.getMsgs1();
            }, 1500)
        });
    }

})
